home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / vesa18.zip / VESA_CL.C < prev    next >
C/C++ Source or Header  |  1995-01-28  |  7KB  |  227 lines

  1. /* VESA package for emx/gcc --- Copyright (c) 1993 by Johannes Martin */
  2. /* vesa_cl.c                --- Copyright (c) 1994 by Laurent Bartholdi */
  3. #include <string.h>
  4. #include <sys/hw.h>
  5.  
  6. #define INCL_VIO
  7. #define INCL_DOSPROCESS
  8.  
  9. #include <os2emx.h>
  10. #include <os2thunk.h>
  11.  
  12. #include "vgaports.h"
  13. #include "vesa.h"
  14. #include "vesadll.h"
  15. #include "common.h"
  16.  
  17. #include <stdio.h>
  18.  
  19. static VESAWORD _Modes[] = { 0x003, 0x012, 0x013,
  20.                              0x101, 0x0102, 0x103, 0x104, 0x105,
  21. #ifdef HICOLOR
  22.                              0x110, 0x113, 0x111, 0x114,
  23.                              0x112,
  24. #endif
  25.                              0xFFFF };
  26.  
  27. static struct _ModeInfo _ModeInfos[] =
  28.     { { 0x1, { 0x0f, 0x7, 0x0, 64, 64, 0x0, 0x0,
  29.                OS2VesaSetWindow, OS2VesaGetWindow, 160,
  30.                640, 400, 8, 16, 1, 4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  31.       { 0x3, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  32.                OS2VesaSetWindow, OS2VesaGetWindow, 80,
  33.                640, 480, 8, 16, 1, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  34.       { 0x3, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  35.                OS2VesaSetWindow, OS2VesaGetWindow, 320,
  36.                320, 200, 8,  8, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  37.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  38.                OS2VesaSetWindow, OS2VesaGetWindow, 640,
  39.                640, 480, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  40.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  41.                OS2VesaSetWindow, OS2VesaGetWindow, 100,
  42.                800, 600, 8, 16, 1, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  43.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  44.                OS2VesaSetWindow, OS2VesaGetWindow, 800,
  45.                800, 600, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  46.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  47.                OS2VesaSetWindow, OS2VesaGetWindow, 128,
  48.                1024, 768, 8, 16, 1, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  49.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  50.                OS2VesaSetWindow, OS2VesaGetWindow, 1024,
  51.                1024, 768, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  52. #ifdef HICOLOR
  53.       { 0xfb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  54.                OS2VesaSetWindow, OS2VesaGetWindow, 640*2,
  55.                640, 480, 8, 16, 1, 16, 1, 6, 0, 1, 5,10, 5, 5, 5, 0, 1, 15 } },
  56.       { 0xfb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  57.                OS2VesaSetWindow, OS2VesaGetWindow, 800*2,
  58.                800, 600, 8, 16, 1, 16, 1, 6, 0, 1, 5,10, 5, 5, 5, 0, 1, 15 } },
  59.       { 0xfb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  60.                OS2VesaSetWindow, OS2VesaGetWindow, 640*2,
  61.                640, 480, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 } },
  62.       { 0xfb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  63.                OS2VesaSetWindow, OS2VesaGetWindow, 800*2,
  64.                800, 600, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 } },
  65.       { 0xfb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  66.                OS2VesaSetWindow, OS2VesaGetWindow, 640*3,
  67.                640, 480, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 } },
  68. #endif
  69.     };
  70.  
  71. VESAWORD *Modes             = _Modes;
  72. struct _ModeInfo *ModeInfos = _ModeInfos;
  73.  
  74. VESABOOL Initialize(void)
  75. {
  76.   _portaccess(0x3c0,0x3df);
  77.   return TRUE;
  78. }
  79.  
  80. VOID ClearUp(void)
  81. {
  82. }
  83.  
  84. VOID *GetPhysBuf(void)
  85. {
  86.   VIOMODEINFO ModeInfo;
  87.   VIOPHYSBUF  PhysBuf;
  88.  
  89.   ModeInfo.cb  = sizeof(ModeInfo);
  90.   VioGetMode(&ModeInfo, 0);
  91.   PhysBuf.pBuf = (PBYTE) ModeInfo.buf_addr;
  92.   PhysBuf.cb   = 0x10000;
  93.   if (VioGetPhysBuf(&PhysBuf, 0) != 0)
  94.     return(NULL);
  95.   else
  96.     return(MAKEP(PhysBuf.asel[0], 0));
  97. }
  98.  
  99. #ifdef HICOLOR
  100.  
  101. unsigned char inindex( unsigned port, unsigned char index )
  102. {
  103.   _outp8( port, index );
  104.   return _inp8( port+1 );
  105. }
  106.  
  107. void outindex( unsigned port, unsigned char index, unsigned char data )
  108. {
  109.   _outp8( port, index );
  110.   _outp8( port+1, data );
  111. }
  112.  
  113. #define OUT8 0x0
  114. #define OUT16 0x1
  115. #define IN8 0x2
  116. #define IN16 0x3
  117. #define OUTI 0x4
  118. #define INI 0x5
  119.  
  120. void playback( unsigned long code[] )
  121. {
  122.   while( *code )
  123.   {
  124.     unsigned opcode = (*code >> 28) & 0xf;
  125.     unsigned port = (*code >> 16) & 0xfff;
  126.     unsigned ax = (*code >> 0) & 0xffff;
  127.     unsigned al = (*code >> 8) & 0xff;
  128.     unsigned data = (*code >> 0) & 0xff;
  129.  
  130.     switch( opcode )
  131.     {
  132.     case OUT8: _outp8( port, al );
  133. #ifdef DEBUG
  134. printf("outp8(0x%X,0x%02X);\n", port, al );
  135. #endif
  136.       break;
  137.     case OUT16: _outp16( port, ax );
  138. #ifdef DEBUG
  139. printf("outp16(0x%X,0x%04X);\n", port, ax );
  140. #endif
  141.       break;
  142.     case IN8: al = _inp8( port );
  143. #ifdef DEBUG
  144. printf("/*%02X=*/inp8(0x%X);\n", al, port );
  145. #endif
  146.       break;
  147.     case IN16: ax = _inp16( port );
  148. #ifdef DEBUG
  149. printf("/*%04X=*/inp16(0x%X);\n", ax, port );
  150. #endif
  151.       break;
  152.     case OUTI: outindex( port, al, data );
  153. #ifdef DEBUG
  154. printf("outindex(0x%X,0x%02X,0x%02X);\n", port, al, data );
  155. #endif
  156.       break;
  157.     case INI: data = inindex( port, al );
  158. #ifdef DEBUG
  159. printf("/*%02X=*/inindex(0x%X,0x%02X);\n", data, port, al );
  160. #endif
  161.     }
  162.     code++;
  163.   }
  164. }
  165.  
  166. #endif
  167.  
  168. VESABOOL SetMode(VESAWORD mode)
  169. {
  170.   VIOMODEINFO m;
  171.  
  172. #ifdef HICOLOR
  173.  
  174. #include "cirrus/3.c"
  175.   playback( mode3 ); /* dirty: resets text mode (3) to ensure we
  176.                         have the proper 8-bit settings */
  177.  
  178. #endif
  179.  
  180.   m.cb     = 12;
  181.   m.fbType = ModeInfos[mode].fbtype & 0x0f;
  182.   m.color  = ModeInfos[mode].Vesa.NumberOfBitsPerPixel;
  183.   m.col    = ModeInfos[mode].Vesa.Width / ModeInfos[mode].Vesa.CharacterWidth;
  184.   m.row    = ModeInfos[mode].Vesa.Height/ ModeInfos[mode].Vesa.CharacterHeight;
  185.   m.hres   = ModeInfos[mode].Vesa.Width;
  186.   m.vres   = ModeInfos[mode].Vesa.Height;
  187.  
  188.   if( m.color > 8 )
  189.     m.color = 8;
  190.  
  191.   return VioSetMode(&m, 0) == 0;
  192. }
  193.  
  194. void SetSpecial(VESAWORD mode)
  195. {
  196. #ifdef HICOLOR
  197.  
  198. #include "cirrus/110.c"
  199. #include "cirrus/111.c"
  200. #include "cirrus/112.c"
  201. #include "cirrus/113.c"
  202. #include "cirrus/114.c"
  203.   switch( _Modes[mode] )
  204.   {
  205.   case 0x110: playback( mode110 ); break;
  206.   case 0x111: playback( mode111 ); break;
  207.   case 0x112: playback( mode112 ); break;
  208.   case 0x113: playback( mode113 ); break;
  209.   case 0x114: playback( mode114 ); break;
  210.   }
  211.  
  212. #endif
  213. }
  214.  
  215. VESABOOL OS2VesaSetWindow(VESACHAR Window, VESAWORD Address)
  216. {
  217.   _outp16(GRA_I, (Address << 12) | 0x09);
  218.   return(TRUE);
  219. }
  220.  
  221. VESABOOL OS2VesaGetWindow(VESACHAR Window, PVESAWORD Address)
  222. {
  223.   _outp8(GRA_I, 0x09);
  224.   *Address = _inp8(GRA_D);
  225.   return(TRUE);
  226. }
  227.